
**********************
***  PREDICTIONS *****
**********************

capt drop _est_*


*****  Polynominal: Trade *******
preserve
gen h1=trade  
bysort id_eez_tax: egen h2=mean(h1) if iyear>=$PriceYearStart & iyear<=$PriceYearEnd
bysort id_eez_tax: egen helpvar=max(h2)
sum helpvar

xtset id_eez_tax iyear
reghdfe collapsed  ///
$Treatment  ///
c.$Treatment#c.helpvar ///
c.$Treatment#c.helpvar#c.helpvar  ///
c.$Treatment#c.helpvar#c.helpvar#c.helpvar   ///
 c.$Treatment#c.helpvar#c.helpvar#c.helpvar#c.helpvar   ///
$ControlsLong ///
, absorb(i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
parmest, label list(parm label estimate min* max* p) ///
saving("${dataOut}Poly_PPR_Trade", replace)
restore


*****  Polynominal: Growth rate *******
preserve
gen helpvar=K 
sum helpvar if $TreatmentGroup==1 , det
local helpvar99=r(p99)
dis `r(p99)'
drop if helpvar>1

xtset id_eez_tax iyear
reghdfe collapsed  ///
$Treatment  ///
c.$Treatment#c.helpvar ///
c.$Treatment#c.helpvar#c.helpvar  ///
$ControlsLong ///
, absorb(i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
parmest, label list(parm label estimate min* max* p) ///
saving("${dataOut}Poly_PPR_K", replace)
restore


*****  Polynominal: Price  *******
preserve
bysort taxonkey: egen hvar=mean(realprice_taxon) if iyear>=$PriceYearStart & iyear<=$PriceYearEnd
bysort taxonkey: egen helpvar=mean(hvar)

drop if helpvar==0
sum helpvar, det
dis `r(p1)'  
dis `r(p99)'
drop if helpvar>=`r(p99)' | helpvar<=`r(p1)'
*drop if helpvar<=`r(p1)'

xtset id_eez_tax iyear
reghdfe collapsed  $Treatment  ///
$ControlsLong ///
c.$Treatment#c.helpvar ///
c.$Treatment#c.helpvar#c.helpvar ///
, absorb(i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
eststo 
parmest, label list(parm label estimate min* max* p) ///
saving("${dataOut}Poly_PPR_Price", replace)
restore


*****  Polynominal: GDP per capita*******

preserve
gen h1=gdp_capita_c /1000
sum h1
bysort id_eez_tax: egen h2=mean(h1) if iyear>=$PriceYearStart & iyear<=$PriceYearEnd
bysort id_eez_tax: egen helpvar=max(h2)
sum helpvar

drop if helpvar==0
sum helpvar, det
dis `r(p99)'
drop if helpvar>`r(p99)' 

xtset id_eez_tax iyear
reghdfe collapsed  ///
$Treatment  ///
c.$Treatment#c.helpvar ///
c.$Treatment#c.helpvar#c.helpvar  ///
c.$Treatment#c.helpvar#c.helpvar#c.helpvar  ///
c.$Treatment#c.helpvar#c.helpvar#c.helpvar#c.helpvar   ///
$ControlsLong ///
, absorb(i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
parmest, label list(parm label estimate min* max* p) ///
saving("${dataOut}Poly_PPR_GDP", replace)
restore



*****  High/low: Tule of Law *******

preserve
drop if law_average==.
gen h1=law_average
bysort id_eez_tax: egen helpvar=mean(h1)
xtile percentile = helpvar, nq(10)
gen HighROL=0
replace HighROL=1 if percentile>=10
drop h1 helpvar percentile

xtset id_eez_tax iyear
reghdfe collapsed  ///
$Treatment  ///
c.$Treatment#c.HighROL ///
$ControlsLong   ///
, absorb(i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
parmest, label list(parm label estimate min* max* p) ///
saving("${dataOut}Poly_High_Low_ROL", replace)

tempfile helpfile0
save `helpfile0'
restore
*******


capt drop _est_*


